/**青蛙眼睛管理类 */
class FaceManager {
	/**单例对象 */
	private static instance: FaceManager;
	/**获取单例对象 */
	public static GetInstance(): FaceManager {
		if (this.instance == null) {
			this.instance = new FaceManager();
		}
		return this.instance;
	}
	/**左眼资源组 */
	private leftEyesRess = [];
	/**右眼资源组 */
	private rightEyesRess = [];
	/**构造 */
	private isFour: boolean = false;
	private constructor() {
		this.GetEyesRes();
	}
	/**获取眼睛图片资源 */
	private GetEyesRes() {
		for (let i = 0; i < 11; i++) {
			let texture = resManager.getInstance().getResGroups(i);
			if (i < 5) {
				this.rightEyesRess.push(texture);
			} else {
				if (i == 10) {
					this.rightEyesRess.push(texture);
					this.leftEyesRess.push(texture);
				} else {
					this.leftEyesRess.push(texture);
				}
			}
		}
		console.log("眼睛资源加载完毕");
	}


	/**更换眼睛资源
	 * @param user 青蛙显示对象
	 * @param type 眼睛状态
	 * @param leftEye 左眼位图
	 * @param rightEye 右眼位图
	 */	
	/**快断线眼 */
	public ChangeWinkEyes(user,leftEye:egret.Bitmap,rightEye:egret.Bitmap) {	
		if (user == null || leftEye == null || rightEye == null) {
			
			return;
		}
		this.ChangeOneEye(user,leftEye, this.leftEyesRess[0], "zuoyan");
		this.ChangeOneEye(user,rightEye, this.rightEyesRess[0], "youyan");
	}
	/**正常眼 */
	public ChangeNormalEyes(user,leftEye:egret.Bitmap,rightEye:egret.Bitmap) {		
		if (user == null || leftEye == null || rightEye == null) {
			return;
		}

		this.ChangeOneEye(user, leftEye, this.leftEyesRess[1], "zuoyan");
		this.ChangeOneEye(user, rightEye, this.rightEyesRess[1], "youyan");
	}
	/**红心眼 */
	public ChangeHeartEyes(user,leftEye:egret.Bitmap,rightEye:egret.Bitmap) {	
		if (user == null || leftEye == null || rightEye == null) {
			return;
		}

		this.ChangeOneEye(user, leftEye, this.leftEyesRess[2], "zuoyan");
		this.ChangeOneEye(user, rightEye, this.rightEyesRess[2], "youyan"); 
	}
	/**断线眼 */
	public ChangeCryEyes(user,leftEye:egret.Bitmap,rightEye:egret.Bitmap) {		
		if (user == null || leftEye == null || rightEye == null) {
			return;
		}

		this.ChangeOneEye(user, leftEye, this.leftEyesRess[3], "zuoyan");
		this.ChangeOneEye(user, rightEye, this.rightEyesRess[3], "youyan");
	}
	/**眩晕眼 */
	public ChangeDizzinessEyes(user,leftEye:egret.Bitmap,rightEye:egret.Bitmap) {
		if (user == null || leftEye == null || rightEye == null) {
			return;
		}

		this.ChangeOneEye(user, leftEye, this.leftEyesRess[4], "zuoyan");
		this.ChangeOneEye(user, rightEye, this.rightEyesRess[4], "youyan");
	}
	/**舔到不同颜色青蛙的眼睛 */
	public ChangeAwkardEyes(user,leftEye:egret.Bitmap,rightEye:egret.Bitmap) {		
		if (user == null || leftEye == null || rightEye == null) {
			return;
		}

		this.ChangeOneEye(user, leftEye, this.leftEyesRess[5], "zuoyan");
		this.ChangeOneEye(user, rightEye, this.rightEyesRess[5], "youyan");
	}



	/**更换单个眼睛
	 * @param user 青蛙显示对象
	 * @param eyeBitmap 眼睛位图
	 * @param texture 要更换的图片资源
	 * @param slotName 插槽名字
	 * @param type 眼睛状态
	 */
	private ChangeOneEye(user, eyeBitmap: egret.Bitmap, texture, slotName: string) {
		//++type;
		var armature = user.armature;
		
		var slot: dragonBones.Slot = armature.getSlot(slotName);
		//slot.display.visible = false;
		eyeBitmap.texture = texture;
		eyeBitmap.width = 77;
		eyeBitmap.height = 77;
		eyeBitmap.x = slot.display.x;
		eyeBitmap.y = slot.display.y;
		eyeBitmap.anchorOffsetX = eyeBitmap.width / 2;
		eyeBitmap.anchorOffsetY = eyeBitmap.height / 2;
		slot.display = eyeBitmap;



		//眩晕
		// if (this.rightEyesRess[4]) {
		// 	// egret.Tween.get(eyeBitmap).to({ rotation: eyeBitmap.rotation + 5760 }, serverConfig.config.propBuffReationTime.dizzy * 10);
		// 	egret.Tween.get(eyeBitmap).to({ rotation: eyeBitmap.rotation + 3600 }, serverConfig.config.propBuffReationTime.dizzy * 10);
		// }
		// else {
		// 	egret.Tween.removeTweens(eyeBitmap);
		// 	eyeBitmap.rotation = 0;
		// }
	}
}